package com.yxw.bamboo.core.send.event.mysql;

import com.yxw.bamboo.core.send.event.EventArgs;
import com.yxw.bamboo.core.send.event.SendEvent;
import com.yxw.bamboo.core.send.event.SqlEventListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class DefaultBeforeMySqlEventListenerImpl implements SqlEventListener {

    @Autowired
    @Qualifier("mySqlDefaultBeforeSendEvent")
    private List<SendEvent> beforeEventList;

    @Override
    public void register(SendEvent sendEvent) {

        beforeEventList.add(sendEvent);
    }

    @Override
    public void trigger(Object eventSource, EventArgs eventArgs) throws Exception {
        for (SendEvent sendEvent:this.beforeEventList) {
            sendEvent.process(eventSource,eventArgs);
        }
    }
}
